package com.starlink.controller.wechat;

import com.github.pagehelper.PageInfo;
import com.starlink.common.WebResponse;
import com.starlink.common.annotation.WebAccess;
import com.starlink.model.request.SearchRecordRequest;
import com.starlink.model.request.mall.MallSearchRequest;
import com.starlink.model.vo.MallCategoryVO;
import com.starlink.model.vo.SearchRecordVO;
import com.starlink.model.vo.mall.MallSearchVO;
import com.starlink.service.MallCategoryService;
import com.starlink.service.SearchRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: zhouyuhang01
 * @Date: 2024/4/2 11:07
 * @Description: WechatMallSearchController
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/wechat/mall")
@Api(value = "【小程序端】商城搜索与分类查询模块", tags = {"【小程序端】商城搜索与分类查询模块"})
public class WechatMallSearchController {
    @Autowired
    private SearchRecordService searchRecordService;
    @Autowired
    private MallCategoryService categoryService;

    @WebAccess(login = true)
    @ApiOperation("商品搜索")
    @PostMapping("/search")
    public WebResponse<PageInfo<List<MallSearchVO>>> search(@RequestBody MallSearchRequest request, Pageable pageable) {
        return WebResponse.build(searchRecordService.search(request,pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("搜索记录查询")
    @PostMapping("/search/select")
    public WebResponse<List<SearchRecordVO>> searchSelect() {
        return WebResponse.build(searchRecordService.searchSelect());
    }

    @WebAccess(login = true)
    @ApiOperation("搜索记录保存")
    @PostMapping("/search/save")
    public WebResponse<Boolean> searchSave(@RequestBody SearchRecordRequest request) {
        return WebResponse.build(searchRecordService.searchSave(request));
    }

    @WebAccess(login = true)
    @ApiOperation("清除搜索记录")
    @GetMapping("/search/deleted")
    public WebResponse<Boolean> searchDeleted(@RequestParam("userId")Long userId) {
        return WebResponse.build(searchRecordService.searchDeleted(userId));
    }

    @WebAccess(login = true)
    @ApiOperation("书籍分类字典查询")
    @GetMapping("/books/category")
    public WebResponse<List<MallCategoryVO>> booksCategory() {
        return WebResponse.build(categoryService.booksCategory());
    }
}
